package xyz.kongbai121.shop.order.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Data
public class OrderConfirmVo {

    /**
     * 收货地址
     */
    List<MemberAddressVo> address;

    /**
     * 所选购物项
     */
    List<OrderItemVo> items;

    /**
     * 优惠信息
     */
    Integer integration;

    /**
     * 库存信息
     */
    Map<Long,Boolean> stocks;

    /**
     * 订单总额
     */
    BigDecimal total;

    /**
     * 应付总额
     */
    BigDecimal payPrice;

    /**
     * 防重令牌
     */
    String orderToken;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public Integer getCount(){
        Integer i = 0;
        if (items != null){
            for (OrderItemVo item : items) {
                i += item.getCount();
            }
        }
        return i;
    }
}
